using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Northwind.NET.FE.Reports
{
    public partial class SalesByCategoryReport : Form
    {
        public SalesByCategoryReport()
        {
            InitializeComponent();
        }

        private void SalesByCategoryReport_FormClosed(object sender, FormClosedEventArgs e)
        {
            //Northwind.NET.FE.Globals.Navigator.UnhideMainSwitchboard();    
        }

        private void SalesByCategoryReport_Load(object sender, EventArgs e)
        {

            // TODO: This line of code loads data into the 'dataModelDataSet.Category' table. You can move, or remove it, as needed.
            this.categoryTableAdapter.Fill(this.dataModelDataSet.Category);
            //MS SQL - string categoryID = null;
            int? categoryID = null;
            this.salesByCategoryTableAdapter.Fill(this.simpleReportsDataSet.SalesByCategory, categoryID);

            this.reportViewer1.RefreshReport();

            this.WindowState = FormWindowState.Maximized;
            
            categoryIdComboBox.SelectedValue = -1;

        
        }

        private void refreshReportButton_Click(object sender, EventArgs e)
        {
            refreshReport(); 
        }

        private void refreshReport()
        {
            //string categoryID = null;
            //if (categoryIdComboBox.SelectedValue != null)
            //    categoryID = categoryIdComboBox.SelectedValue.ToString();
            int? categoryID = null;
            if (categoryIdComboBox.SelectedValue != null)
                categoryID = Int32.Parse( categoryIdComboBox.SelectedValue.ToString() );

            this.salesByCategoryTableAdapter.Fill(this.simpleReportsDataSet.SalesByCategory, categoryID);

            this.reportViewer1.RefreshReport();
        }

        public void RefreshForCategory(string categoryId)
        {
            categoryIdComboBox.SelectedValue = categoryId;
            refreshReport(); 
        }
    }
}